package l1j.opqlo.NewSystem.鑑定系統;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.DatabaseFactory;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.utils.SQLUtil;

public abstract class IdentifiedModel {
	private static final Logger _log = Logger.getLogger(IdentifiedModel.class.getName());

	protected void executeUpdate(int objId, String sql, double updateNum){
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement(sql.toString());
			pstm.setDouble(1, updateNum);
			pstm.setInt(2, objId);
			pstm.execute();
		} catch (final SQLException e) {
			_log.log(Level.SEVERE , e.getLocalizedMessage() , e);
		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	protected void executeUpdate(int objId, String sql, int updateNum){
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement(sql.toString());
			pstm.setInt(1, updateNum);
			pstm.setInt(2, objId);
			pstm.execute();
		} catch (final SQLException e) {
			_log.log(Level.SEVERE , e.getLocalizedMessage() , e);
		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	protected void executeUpdate(int objId, String sql, String updateNum) {
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = DatabaseFactory.get().getConnection();
			pstm = con.prepareStatement(sql.toString());
			pstm.setString(1, updateNum);
			pstm.setInt(2, objId);
			pstm.execute();
		} catch (final SQLException e) {
			_log.log(Level.SEVERE , e.getLocalizedMessage() , e);
		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	public abstract void setStatus(L1PcInstance pc, L1ItemInstance item,int min, int max);
}
